(function (vc) {
    vc.extends({
        propTypes: {
            emitChooseProduct: vc.propTypes.string,
            emitLoadData: vc.propTypes.string
        },
        data: {
            chooseProductInfo: {
                products: [],
                _currentProductName: '',
            }
        },
        _initMethod: function () {
        },
        _initEvent: function () {
            vc.on('chooseProduct', 'openChooseProductModel', function (_param) {
                $('#chooseProductModel').modal('show');
                $that._refreshChooseProductInfo();
                $that._loadAllProductInfo(1, 10, '');
            });
            vc.on('chooseProduct', 'setProducts', function (_param) {
                $('#chooseProductModel').modal('show');
                $that._refreshChooseProductInfo();
                $that.chooseProductInfo.products = _param;
            });
        },
        methods: {
            _loadAllProductInfo: function (_page, _row, _name) {
                var param = {
                    params: {
                        page: _page,
                        row: _row,
                        name: _name
                    }
                };
                //发送get请求
                vc.http.apiGet('/product.queryProduct',
                    param,
                    function (json) {
                        var _productInfo = JSON.parse(json);
                        $that.chooseProductInfo.products = _productInfo.data;
                    }, function () {
                        console.log('请求失败处理');
                    }
                );
            },
            chooseProduct: function (_product) {
                vc.emit($props.emitChooseProduct, 'chooseProduct', _product);
                $('#chooseProductModel').modal('hide');
            },
            queryProducts: function () {
                $that._loadAllProductInfo(1, 10, $that.chooseProductInfo._currentProductName);
            },
            _refreshChooseProductInfo: function () {
                $that.chooseProductInfo._currentProductName = "";
            }
        }
    });
})(window.vc);
